﻿using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WQLWebAPI.Api.Configuration
{
    public static class AuthenticationConfig
    {
        public static void ConfigAuthentication(this IServiceCollection services, IConfiguration configuration)
        {


            services.AddAuthentication(opt=> {
                opt.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                opt.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            })
                 .AddJwtBearer("Bearer", options =>
                 {
                     //options.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters
                     //{
                     //    RoleClaimType = "role",NameClaimType="name"

                     //};
                     //var configUrl = new ConfigurationBuilder().AddJsonFile("host.json", false, true).Build()["authUrls"];
                     var configUrl = configuration["authUrls"];
                     options.Authority = configUrl;
                     options.RequireHttpsMetadata = false;
                     options.Audience = "AntennaKnowbaseApi";
                   
                 });

        }
    }
}
